﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.BLL;
using HNQXYJ.Model;

namespace HNQXYJ.DataCenterJS
{
    public partial class TerminalGetAllData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //string procName = "TerminalGetDataAll";
                //this.RpList.DataSource = TerminalBLL.GetTerminalTable(procName);
                //this.RpList.DataBind();
                DataBind(1);
            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           
        }

        protected void PrePage_Click(object sender, EventArgs e)
        {
            int currPage = Convert.ToInt32(LbPageNumber.Text);
            currPage--;
            this.DataBind(currPage);
        }

        protected void NextPage_Click(object sender, EventArgs e)
        {
            int currPage = Convert.ToInt32(LbPageNumber.Text);
            currPage++;
            this.DataBind(currPage);
        }

        //页面跳转
        protected void BtnGo_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int pageNumber = Convert.ToInt32(txtPageNumber.Text);
                this.DataBind(pageNumber);
            }
        }


        /// <summary>
        /// 获取某一页的数据
        /// </summary>
        /// <param name="pageNumber"></param>
        private void DataBind(int pageNumber)
        {
            int pageCount = TerminalBLL.GetTerminalPageCount(20);//设定20行为一页
            if (pageNumber < 1)
            {
                pageNumber = 1;
            }
            if (pageNumber > pageCount)
            {
                pageNumber = pageCount;
            }

            this.btnPrePage.Enabled = this.btnNextPage.Enabled = true;

            if (pageNumber == 1)
            {
                this.btnPrePage.Enabled = false;
            }

            if (pageNumber == pageCount)
            {
                this.btnNextPage.Enabled = false;
            }

            List<Terminal> list = new List<Terminal>();
            list = TerminalBLL.GetDataByPage(pageNumber,20);
            this.RpList.DataSource = list;
            this.RpList.DataBind();

            LbPageNumber.Text = pageNumber.ToString();
            LbPageCount.Text = pageCount.ToString();
            txtPageNumber.Text = pageNumber.ToString();
            
 
        }

       
    }
}